package com.graduation.rescuematerial.utils;

import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.core.toolkit.Assert;
import com.google.common.collect.Maps;
import com.graduation.rescuematerial.dto.LogisticDTO;
import com.graduation.rescuematerial.vo.LogisticApiResult;
import com.graduation.rescuematerial.vo.LogisticVO;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;

import java.util.Map;

/**
 * @Author:CaiShuangLian
 * @FileName:
 * @Date:Created in  2022/5/14 14:51
 * @Version:
 * @Description:TODO
 */

@Slf4j
public class LogisticUtil {

    public static LogisticVO getLogisticInfo(LogisticDTO params) {
        String no = params.getNo();
        String type = params.getType();
        String appCode = "51b7101a57d14a918ccd63bb120eb742";

        // 请求地址
        String requestUrl = String.format("https://kdwlcxf.market.alicloudapi.com/kdwlcx?no=%s&type=%s",
                no, StringUtils.isBlank(type) ? "" : type);
        // 发起请求
        Map<String, String> headerMap = Maps.newHashMap();
        headerMap.put("Authorization", String.format("APPCODE %s", appCode));
        String resultJson = HttpUtil.getUrl(requestUrl, headerMap);
        LogisticApiResult logisticApiResult = JSON.parseObject(resultJson, LogisticApiResult.class);
        Assert.notNull(logisticApiResult, "参数异常");
        Assert.isTrue(logisticApiResult.getStatus() == 0, logisticApiResult.getMsg());
        return logisticApiResult.getResult();
    }

}
